﻿using System;
using System.Collections.Generic;
using Jayden.Dll.Web.HtmlControls.Descriptions;
using Jayden.Dll.Web.HtmlControls.Generics;
using Jayden.Dll.Web.HtmlControls.Interfaces;

namespace Jayden.Dll.Web.HtmlControls
{
	public class Textarea : HtmlElement, WithName, WithDisabled, WithReadOnly, WithMaxLength, WithAutoFocus, WithRequired, WithPlaceholder, WithRows, WithCols, WithForm
	{
		public Textarea() : base(TextareaDescription.Instance) { }

		public string Name { get { return this["name"]; } set { this["name"] = value; } }
		public bool Disabled { get { return GetAttributeBool("disabled"); } set { SetAttribute("disabled", value); } }
		public bool Enabled { get { return !Disabled; } set { Disabled = !value; } }
		public bool ReadOnly { get { return GetAttributeBool("readonly"); } set { SetAttribute("readonly", value); } }
		public bool Required { get { return GetAttributeBool("required"); } set { SetAttribute("required", value); } }
		public bool AutoFocus { get { return GetAttributeBool("autofocus"); } set { SetAttribute("autofocus", value); } }
		public uint? MaxLength { get { return GetAttributeUint("maxlength"); } set { SetAttribute("maxlength", value); } }
		public string Placeholder { get { return this["placeholder"]; } set { this["placeholder"] = value; } }
		public uint? Cols { get { return GetAttributeUint("cols"); } set { SetAttribute("cols", value); } }
		public uint? Rows { get { return GetAttributeUint("rows"); } set { SetAttribute("rows", value); } }
		public string Form { get { return this["form"]; } set { this["form"] = value; } }
		public string DirName { get { return this["dirname"]; } set { this["dirname"] = value; } }
		public string Wrap { get { return this["wrap"]; } set { this["wrap"] = value; } }

		protected override void TranslateAttributes(Core.Translations.ITranslator translator)
		{
			base.TranslateAttributes(translator);
			Placeholder = translator.Translate(Placeholder);
		}

	}
	public class TextareaDescription : HtmlElementDescription
	{
		public static readonly TextareaDescription Instance = new TextareaDescription();
		private TextareaDescription() : base("textarea") { }
		public override string Description { get { return "multi-line plain-text edit control for the element’s raw value."; } }
		public override Type ControlType { get { return typeof(Textarea); } }
		public override bool IsPhrasingElement { get { return true; } }
		public override bool AllowFlowContent { get { return false; } }
		public override bool AllowPhrasingContent { get { return false; } }
		public override bool AllowInnerText { get { return true; } }
		public override IEnumerable<HtmlElementDescription> PermittedElements { get { yield break; } }
	}
}
